package ge.telasi.tasks.model.validation;

import ge.telasi.tasks.LocaleManager;
import ge.telasi.tasks.TaskException;

/**
 * @author dimitri
 */
public class FileValidator extends Validator {
    public static final int MAX_SIZE_MB = 50;
    public static final int MAX_SIZE = MAX_SIZE_MB * 1024 * 1024;

    public void validateLength(long length) {
        if (length > MAX_SIZE) {
            LocaleManager lm = getLocaleManager();
            String msg = lm.getMessage("FileValidator.sizeTooLarge", MAX_SIZE_MB);
            throw new TaskException(msg);
        }
    }

    public void validateName(String fileName) {
        String value = fileName;
        String name = "File.name";
        new EmptyFieldValidator().validate(name, value);
        new TextRangeValidator(0, 255).validate(name, value);
    }

}
